package com.ruoyi.framework.config;

import com.ruoyi.videoHandler.VideoStreamHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.client.standard.StandardWebSocketClient;

/**
 * @projectName: intelligent-monitor
 * @package: com.ruoyi.framework.config
 * @className: StartConfig
 * @author: 寇耕耀
 */
@Component
public class StartConfig implements CommandLineRunner {
    @Autowired
    private VideoStreamHandler videoStreamHandler;

    @Override
    public void run(String... args) throws Exception {
        StandardWebSocketClient webSocketClient = new StandardWebSocketClient();
        ListenableFuture<WebSocketSession> future = webSocketClient.doHandshake(videoStreamHandler, "ws://localhost:8888/wss");
        WebSocketSession webSocketSession = future.get();
        while (true) {
            java.util.Scanner scanner = new java.util.Scanner(System.in);
            if (scanner.next() != null) {
                webSocketSession.close();
                break;
            }
        }
    }
}
